﻿using System;
using System.Text;
using Orid.Data.SqlServer;

namespace Orid.Management.Statistics.Tools.Decomposition.Data
{
    class Account:DataBase
    {
        #region 虚函数
        public virtual string GetLoginName(int? accountID)
        {
            return null;
        }
        #endregion

        #region  GetLoginName 实现

        protected   string GetLoginName(int? accountID,string connectString,string tableName)
        {
            string LoginName = string.Empty;
            try
            {

                if (accountID == null)
                {
                    return null;
                }

                StringBuilder sqlText = new StringBuilder();
                sqlText.Append(" SELECT	 [Accounts] .[LoginName]");
                sqlText.Append("  FROM  " + tableName + "  [Accounts] with(NOLOCK) ");//readpast
                sqlText.Append(" WHERE [AccountID] = @AccountID");

                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
                {
                    conn.Open();
                    System.Data.SqlClient.SqlParameter[] SqlParameter;
                    SqlParameter = new System.Data.SqlClient.SqlParameter[]
                                 {    
                                       new System.Data.SqlClient.SqlParameter("@AccountID",System.Data.SqlDbType.Int), 

                                 };

                    SqlParameter[0].Value = accountID;

                    object name = SqlHelper.ExecuteScalar(conn, System.Data.CommandType.Text, sqlText.ToString(), SqlParameter);
                    if ((name !=null)&&(name != DBNull.Value))
                    {
                        LoginName = name.ToString();
                    }

                    if (conn.State == System.Data.ConnectionState.Open)
                        conn.Close();


                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw (new Exception(ex.Message));
            }
            return LoginName;
        }

        #endregion
    }
}
